﻿using System;

namespace Finance.Data
{
	public interface IDataBaseObject
	{
		Guid Id { get; set; }
		void Save();
	}
	
	public abstract class DataBaseObject : IDataBaseObject
	{
		public DataBase DataBase
		{
			get { return ParentCollection.DataBase; }
		}

		protected readonly DataBaseObjectCollection ParentCollection;
		public Guid Id { get; set; }

		protected DataBaseObject(DataBaseObjectCollection parentCollection)
		{
			ParentCollection = parentCollection;
		}

		public override string ToString()
		{
			return Id.ToString();
		}

		public virtual void Save()
		{
			ParentCollection.Save(this);
		}
	}
}
